/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements.  See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


/*************************************************************************
 * File: event_iocp.h
 *************************************************************************
 *\author: starlove
 *************************************************************************/

#ifdef __MLSE_PLATFORM_WIN__

#ifndef __MLSE_EVENT_IOCP_H__
#define __MLSE_EVENT_IOCP_H__

#include <network/event.h>
#include <windows.h>

typedef struct __XOVERLAPPED
{
    OVERLAPPED			ol;
    char				optype;
    void				*op;
    __XOVERLAPPED		*next;
    __XOVERLAPPED()
    {
        Reset();
    }

    void Reset()
    {
        //op = NULL;
        memset(&ol, 0, sizeof(ol));
        next = NULL;
    }
} XOVERLAPPED, *LPXOVERLAPPED;

class CIOCPEventIO : public IEventIO
{
public:
    CIOCPEventIO();
    ~CIOCPEventIO();
    //////////////////////////////////////////////////////////////////////////
    /// Query io_events
    //////////////////////////////////////////////////////////////////////////
    virtual LPEVENT Query(unsigned int &ev_count, unsigned int time_out = INFINITE);
    //////////////////////////////////////////////////////////////////////////
    /// Bind io-handle to IO
    //////////////////////////////////////////////////////////////////////////
    virtual bool Bind(EVHANDLE hd);
    //////////////////////////////////////////////////////////////////////////
    /// Set the IO-Handle
    //////////////////////////////////////////////////////////////////////////
    virtual bool Init(HANDLE handleIOCP);
    virtual bool Init();
    //////////////////////////////////////////////////////////////////////////
    /// Post event to the IO-Handle
    //////////////////////////////////////////////////////////////////////////
    void Post(LPEVENT ev);
	/// Return io handle
	HANDLE GetIOHandle();

private:
    HANDLE m_handleIOCP;
};

#endif //

#endif //__MLSE_PLATFORM_WIN__
